<template>
  <div>
    <el-form :model="dataForm" ref="dataForm" label-width="100px" size="small" :rules="rules">
      <el-form-item label="标签名称:" prop="labelName">
        <el-input v-model="dataForm.labelName" placeholder="请输入标签名称" maxlength="30" clearable></el-input>
      </el-form-item>
      <el-form-item label="标签简介:" prop="labelDesc">
        <el-input v-model="dataForm.labelDesc" placeholder="请输入标签简介" maxlength="30" clearable></el-input>
      </el-form-item>
      <el-form-item style="margin-top: 10px" label-width="130px">
        <el-button type="" size="small" @click="close">
          取消
        </el-button>
        <el-button type="primary" @click="submit">
          <fa-icon class="fa-check" />提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { CONSTANT_OBJ } from '@/utils/constant'
import api from '../api'
export default {
  data () {
    return {
      dataForm: {
        labelName: '',
        labelDesc: ''
      },
      rules: {
        labelName: [{ required: true, message: '请输入标签名称', trigger: 'blur' }],
        labelDesc: [{ required: true, message: '请输入标签简介', trigger: 'blur' }]
      }
    }
  },
  methods: {
    /**
     * 提交代码
     */
    submit () {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          api.postAddLabelData(this.dataForm).then(res => {
            const { responseCode, responseMsg } = res
            if (responseCode === CONSTANT_OBJ.RES_SUCCESS) {
              this.$message({
                message: `${responseMsg}`,
                type: 'success'
              })
              this.$emit('uppdataSuccess', 'label')
            }
          })
        }
      })
    },
    close () {
      this.$emit('close')
    }
  }
}
</script>
